# -*- mode: makefile -*-

export GOOS=linux

REGISTRY ?= quay.io
IMAGE ?= openshift/openshift-router
TAG ?= latest

new-openshift-router-image:
	GO111MODULE=on CGO_ENABLED=0 GOFLAGS=-mod=vendor go build -o openshift-router -gcflags=all="-N -l" ./cmd/openshift-router
	imagebuilder -t $(IMAGE):$(TAG) -f hack/Dockerfile.debug .

push:
	docker tag $(IMAGE):$(TAG) $(REGISTRY)/$(IMAGE):$(TAG)
	docker push $(REGISTRY)/$(IMAGE):$(TAG)

set-image:
	oc scale --replicas 0 -n openshift-cluster-version deployments/cluster-version-operator
	oc scale --replicas 0 -n openshift-ingress-operator deployments ingress-operator
	oc -n openshift-ingress scale deployment --replicas=0 router-default
	oc -n openshift-ingress patch deployment router-default -p '{"spec":{"template":{"spec":{"$$setElementOrder/containers":[{"name":"router"}],"containers":[{"imagePullPolicy":"Always","name":"router"}]}}}}'
	oc -n openshift-ingress set image deployment/router-default router=$(REGISTRY)/$(IMAGE):$(TAG)
	oc -n openshift-ingress scale deployment --replicas=1 router-default

dwim:  new-openshift-router-image push set-image

reset:
	oc scale --replicas 1 -n openshift-cluster-version deployments/cluster-version-operator
	oc scale --replicas 1 -n openshift-ingress-operator deployments ingress-operator
